<?php
Zend::loadClass('Lead_EDO_Datatype_Field');

/**
 * Datatype for date
 * 
 * @package EDO
 * @subpackage Datatypes
 *
 */
class Lead_EDO_Datatype_Date extends Lead_EDO_Datatype_Field 
{
	protected $_SQLValueIsQuoted = true;

	protected $pattern = '/^\d{4}-\d{1,2}-\d{1,2}$/';
		
	function validate($validate)
	{
		if((is_null($validate) OR $validate == '') AND !$this->notNull())
			return null;
			
		$validate = preg_replace("/^(\d{1,2})\.(\d{1,2})\.(\d{4})/", "$3-$2-$1", $validate);
		if(is_string($validate))
		{
			if(preg_match($this->pattern, $validate))
			{
				return $validate;
				
			}
			
			
		}
	
				
		return false;
	}
	
	
	public function getDisplayValue()
	{
			    
	    return preg_replace('/^(\d{4})-(\d{1,2})-(\d{1,2})$/', "$3.$2.$1", $this->getValue());
	}
	
	
}